package com.hxh.learn.vo;

import cn.hutool.core.date.DateUtil;
import cn.hutool.crypto.SecureUtil;
import com.hxh.learn.model.SysUser;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import javax.validation.constraints.NotBlank;


/**
 * @Author: hxh
 * @Date: 2023/3/2
 */
@Data
@ApiModel(value = "SysUser对象", description = "用户")
public class SysUserInsertVo {

    @NotBlank(message = "姓名不能为空")
    @ApiModelProperty(value = "姓名",required = true)
    private String userName;

    @ApiModelProperty("用户昵称")
    private String userNick;

    @ApiModelProperty("状态：0停用，1启用")
    private Integer userStatus;

    @ApiModelProperty("手机号")
    private String userPhone;

    @ApiModelProperty("用户头像url")
    private String userAvatar;

    @NotBlank(message = "密码不能为空")
    @ApiModelProperty(value = "密码",required = true)
    private String userPossword;

    public SysUser convert(){
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        SysUser user = new SysUser();
        user.setUserName(userName);
        user.setUserNick(userNick);
        user.setUserStatus(userStatus);
        user.setUserPhone(userPhone);
        user.setUserAvatar(userAvatar);
        user.setUserPossword(passwordEncoder.encode(userPossword));
        user.setCreateTime(DateUtil.current());
        return user;

    }


}
